<template>
  <el-container>
    <el-header>
      <el-row>
        <el-col :span="6">
          <el-input v-model="input" placeholder="请输入药品">
          </el-input>
        </el-col>
        <el-col :span="6">
          <el-button>查询</el-button>
        </el-col>
        <el-col :span="6">
          <el-button @click="getDrugDosByConst()">新增</el-button>
        </el-col>
        <el-dialog :visible.sync="dialogVisible">
          <span>新增药品</span><br>
          <el-form :model="addDrugForm" label-width="80px">
            <el-form-item label="药品编码">
              <el-input v-model="addDrugForm.drugsCode"></el-input>
            </el-form-item>
            <el-form-item label="药品名称">
              <el-input v-model="addDrugForm.drugsName"></el-input>
            </el-form-item>
            <el-form-item label="药品单价">
              <el-input v-model="addDrugForm.drugsPrice"></el-input>
            </el-form-item>
            <el-form-item label="药品剂型">
              <el-select v-model="addDrugForm.drugsDosageID" placeholder="请选择">
                <el-option v-for="item in drugsDosage"
                  :key="item.ID"
                  :label="item.ConstantName"
                  :value="item.ID">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="药品类型">
              <el-select v-model="addDrugForm.drugsTypeID" placeholder="请选择">
                <el-option v-for="item in drugsType"
                  :key="item.ID"
                  :label="item.ConstantName"
                  :value="item.ID">
                </el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
              <el-button @click="dialogVisible = false">取 消</el-button>
              <el-button type="primary" @click="addNewDrug()">确 定</el-button>
          </span>
        </el-dialog>
        <el-col :span="6">
          <el-button>导入</el-button>
        </el-col>
      </el-row>
    </el-header>
    <el-container>

    </el-container>
  </el-container>
</template>
<script>
import {postRequest} from '../../utils/ajaxapi'
import {getRequest} from '../../utils/ajaxapi'
export default {
  data() {
    return {
      input: '',
      dialogVisible:false,
      addDrugForm:{
        drugsName:'',
        drugsCode:'',
        drugsPrice:'0',
        drugsDosageID:''
      },
      drugsDosage:[{
        ConstantCode:"",
        ConstantTypeID:'',
        ConstantName:"",
        ID:'',
        DelMark:''
       }],
       drugsType:[{
         ConstantCode:"",
         ConstantTypeID:'',
         ConstantName:"",
         ID:'',
         DelMark:''
       }]
    }
  },
  methods:{
    //增加药品
    addNewDrug(){
      let _this = this;
      postRequest("/drugmage/addNewDrug",this.addDrugForm)
      .then(function(response){
        _this.addDrugForm.drugsName = response.data.drugsName
      })
    },
    //查询药品类型和药品剂型
    getDrugDosByConst(){
      let _this = this;
      this.dialogVisible = true;
      getRequest("/constantItem/getConstantItemByTypeid?typeid=11")
      .then(function(response){
        _this.drugsDosage = response.data;
      });
      getRequest("/constantItem/getConstantItemByTypeid?typeid=10")
      .then(function(response){
        _this.drugsType = response.data;
      })
    }
  }
}
</script>
